/*
 * Copyright 2007-2022 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.xajtfb.bus.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.*;
import com.xci.xajtfb.bus.entity.VideosInfo;
import com.xci.xajtfb.bus.entity.WxNewsinformation;
import com.xci.xajtfb.bus.filter.WxNewsinformationFilter;
import com.xci.xajtfb.bus.service.WxNewsinformationService;
import com.github.lvyanyang.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/**
 * 交通资讯接口
 * @author 王彦红 wangyanhong@xci96716.com
 * @since 2022-02-10 14:06:00
 */
@Api(tags = "交通资讯接口")
@Authorize
@RestController
@RequestMapping(value = "/api/bus/wxNewsinformation", produces = Const.PROJSON)
public class WxNewsinformationApiController extends BaseController {
    /** 交通资讯服务 */
    @Resource private WxNewsinformationService wxNewsinformationService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "根据主键查询单个交通资讯")
    @PostMapping("/selectById")
    public BoolResult<WxNewsinformation> selectById(@RequestBody IdBody body) {
        return BoolResult.success(wxNewsinformationService.selectById(body.getId().intValue()));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查询交通资讯分页列表")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<WxNewsinformation>> selectPageList(@RequestBody WxNewsinformationFilter filter) {
        return BoolResult.success(wxNewsinformationService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "查询视频信息")
    @PostMapping("/selectVideosInfo")
    public BoolResult<List<VideosInfo>> selectVideosInfo() {
        //读取 json 返回视频信息
        List<VideosInfo> list =null;
        try {
            //XCI.buildRootFile("/videosinfo.josn")
            JsonListData jsonListData = new JsonListData( ResourceUtils.getFile("classpath:jsondata/videosinfo.josn"),VideosInfo.class) ;
            list =jsonListData.getInnerList();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


        return BoolResult.success(list);
    }
}